<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
      .box{
          position: relative;
          width: 500px;
          height: 100px;
          border:1px solid black;
      }   
      .box p{
          position: absolute;
          left: 50%;
          width: 100px;
          height: 100px;
          padding: 0 20px;
          /*第二种水平居中方式替换transform：margin-left:-70px;*/
          transform: translate(-50%);
          background-color: burlywood;
      }
    </style>
</head>
<body>
  <div class="box">
      <p></p>
  </div>  
</body>
</html>